<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="dialog.js"></script>

<script type="text/javascript">
document.write ("<link href='../skin/" + config.Skin + "/dialog.css' type='text/css' rel='stylesheet'>");

document.write ("<TITLE>" + lang["DlgExcel"] + "</TITLE>");

var eWebEditorActiveX;

function ok(){
	if (!dialogArguments.CheckActiveXVersion()){
		var arr = showModalDialog("installactivex.htm", dialogArguments, "dialogWidth:0px;dialogHeight:0px;help:no;scroll:no;status:no");
		return;
	}

	if (d_sheet.length<=0){
		alert(lang["DlgExcelInvalidFile"]);
		return;
	}
	
	var n_Index = d_sheet.options[d_sheet.selectedIndex].value;
	var s_File = d_file.value;
	var s_PostUrl = getSitePath() + getWebEditorRootPath() + "/" + config.ServerExt + "/upload." + config.ServerExt + "?action=local&type=local&style=" + config.StyleName + "&cusdir=" + config.CusDir;

	var n_OptimizeMode = 1;
	if (d_opt2.checked){
		n_OptimizeMode = 2;
	}

	var b_opt1vml = d_opt1vml.checked;
	var b_opt1space = d_opt1space.checked;
	var b_opt1table = d_opt1table.checked;
	var b_opt1overflow = d_opt1overflow.checked;

	var b_opt2image = d_opt2image.checked;
	var b_opt2space = d_opt2space.checked;
	var b_opt2table = d_opt2table.checked;

	divProcessing.style.display="";
	if (eWebEditorActiveX){eWebEditorActiveX=null}
	eWebEditorActiveX = new ActiveXObject("eWebEditorClient.eWebEditor");
	eWebEditorActiveX.ImportExcelSheet(s_File, n_Index, s_PostUrl, n_OptimizeMode, b_opt1vml, b_opt1space, b_opt1table, b_opt1overflow, b_opt2image, b_opt2space, b_opt2table);
	window.setTimeout("CheckActiveXStatus()", 100);
}

function CheckActiveXStatus(){
	if (eWebEditorActiveX.Status!="ok"){
		window.setTimeout("CheckActiveXStatus()", 100);
		return;
	}

	var s_Error = eWebEditorActiveX.Error;
	if (s_Error!=""){
		var s_ErrorCode = s_Error.substring(0,s_Error.indexOf(":"));
		switch(s_ErrorCode){
		case "InvalidFile":
			alert(lang["DlgExcelInvalidFile"]);
			break;
		default:
			alert(s_Error);
		}
		divProcessing.style.display="none";
		return;
	}

	var s_Style = eWebEditorActiveX.Style;
	if (d_opt2.checked){
		s_Style = "";
	}

	var s_Body = eWebEditorActiveX.Body;

	var s_OriginalFiles = eWebEditorActiveX.OriginalFiles;
	var s_SavedFiles = eWebEditorActiveX.SavedFiles;
	if (s_OriginalFiles){
		var a_Original = s_OriginalFiles.split("|");
		var a_Saved = s_SavedFiles.split("|");
		for (var i=0; i<a_Original.length; i++){
			if (a_Saved[i]){
				var s_OriginalFileName = a_Original[i];
				var s_SaveFileName = a_Saved[i].substr(a_Saved[i].lastIndexOf("/")+1);
				var s_SavePathFileName = a_Saved[i];
				dialogArguments.addUploadFile(s_OriginalFileName, s_SaveFileName, s_SavePathFileName);
			}
		}
	}
	
	if (d_pos.checked){
		dialogArguments.setHTML(s_Style + s_Body, true);
	}else{
		dialogArguments.insertHTML(s_Body);
		if (s_Style){
			dialogArguments.setHTML(s_Style+dialogArguments.getHTML(), true);
		}
	}

	eWebEditorActiveX = null;
	divProcessing.style.display="none";

	window.returnValue = null;
	window.close();
}



var s_LastFile = "";
function DoGetExcelSheet(){
	if (!dialogArguments.CheckActiveXVersion()){
		var arr = showModalDialog("installactivex.htm", dialogArguments, "dialogWidth:0px;dialogHeight:0px;help:no;scroll:no;status:no");
		return;
	}

	var s_File = BaseTrim(d_file.value);
	if ((s_LastFile!=s_File)){
		d_sheet.options.length = 0;
		s_LastFile="";
	}
	if (s_File=="") {return;}
	if (s_File.indexOf(":")<0){return;}
	if ((s_LastFile!="")&&(s_LastFile==s_File)) {return;}
	
	if (!IsExt(s_File, "xls")){
		return;
	}

	if (eWebEditorActiveX){eWebEditorActiveX=null}
	eWebEditorActiveX = new ActiveXObject("eWebEditorClient.eWebEditor");

	var s_Sheets = eWebEditorActiveX.GetExcelWorkSheetName(s_File);
	var s_Error = eWebEditorActiveX.Error;
	if (s_Error!=""){
		var s_ErrorCode = s_Error.substring(0, s_Error.indexOf(":"));
		if (s_ErrorCode!="InvalidFile"){
			alert(s_Error);
			return;
		}
	}
	
	var a_Sheets = s_Sheets.split("\n");
	for (var i=0; i<a_Sheets.length; i++){
		d_sheet.options[d_sheet.options.length] = new Option(a_Sheets[i], i+1);
	}
	s_LastFile = s_File;
	
	eWebEditorActiveX = null;
}

function clickOpt(index){
	var el_group,els;
	
	for (var i=1; i<=2; i++){
		el_group = document.getElementById("group_opt"+i);
		els = el_group.getElementsByTagName("INPUT");
		for (var j=0; j<els.length; j++){
			if (index==i){
				els[j].disabled=false;
			}else{
				els[j].disabled=true;
			}
		}

		els = el_group.getElementsByTagName("SPAN");
		for (var j=0; j<els.length; j++){
			if (index==i){
				els[j].disabled=false;
			}else{
				els[j].disabled=true;
			}
		}
	}
}

function InitDocument(){
	lang.TranslatePage(document);
	adjustDialog();
	clickOpt(1);
	adjustProcessingPos();
}

function adjustProcessingPos(){
	var el = document.getElementById("divProcessing");
	el.style.left = (tabDialogSize.offsetWidth+6-parseInt(el.style.width))/2 + "px";
	el.style.top = (tabDialogSize.offsetHeight-parseInt(el.style.height))/2 + "px";
}

</script>


<BODY onload="InitDocument()">



<table border=0 cellpadding=0 cellspacing=5 id=tabDialogSize><tr><td>

<table border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
	<td>
	<fieldset>
	<legend><span lang=DlgExcelLegend></span>:</legend>
	<table border=0 cellpadding=5 cellspacing=0 width="100%">
	<tr><td>

		<table border=0 cellpadding=0 cellspacing=2 width="100%">
		<tr>
			<td noWrap><span lang=DlgExcelFile></span>:</td>
			<td noWrap width="100%"><input type=file id="d_file" size=30 style="width:100%" onchange="DoGetExcelSheet()" onkeyup="DoGetExcelSheet()"></td>
		</tr>
		<tr>
			<td noWrap><span lang=DlgExcelSheet></span>:</td>
			<td noWrap><select id="d_sheet" size=1 style="width:100%"></select></td>
		</tr>
		</table>

	</td></tr>
	</table>
	</fieldset>
	</td>
</tr>
<tr><td height=5></td></tr>
<tr>
	<td>
	<fieldset>
	<legend><span lang=DlgExcelOptimize></span>:</legend>
	<table border=0 cellpadding=5 cellspacing=0 width="100%">
	<tr><td>

		<table border=0 cellpadding=0 cellspacing=3>
		<tr><td colspan=5 noWrap><input type=radio name="d_optimize" id="d_opt1" checked onclick="clickOpt(1)"><label for=d_opt1><span lang=DlgExcelOpt1></span></label></td></tr>
		<tr id=group_opt1>
			<td>&nbsp;&nbsp;&nbsp; </td>
			<td noWrap><input type=checkbox id=d_opt1vml checked><label for=d_opt1vml><span lang=DlgExcelOpt1VML></span></label></td>
			<td noWrap><input type=checkbox id=d_opt1space><label for=d_opt1space><span lang=DlgExcelOpt1Space></span></label></td>
			<td noWrap><input type=checkbox id=d_opt1table checked><label for=d_opt1table><span lang=DlgExcelOpt1Table></span></label></td>
			<td noWrap><input type=checkbox id=d_opt1overflow><label for=d_opt1overflow><span lang=DlgExcelOpt1Overflow></span></label></td>
		</tr>
		<tr><td colspan=5 noWrap><input type=radio name="d_optimize" id="d_opt2" onclick="clickOpt(2)"><label for=d_opt2><span lang=DlgExcelOpt2></span></label></td></tr>
		<tr id=group_opt2>
			<td>&nbsp; </td>
			<td noWrap><input type=checkbox id=d_opt2image checked><label for=d_opt2image><span lang=DlgExcelOpt2Image></span></label></td>
			<td noWrap><input type=checkbox id=d_opt2space><label for=d_opt2space><span lang=DlgExcelOpt2Space></span></label></td>
			<td noWrap><input type=checkbox id=d_opt2table checked><label for=d_opt2table><span lang=DlgExcelOpt2Table></span></label></td>
			<td></td>
		</tr>
		</table>

	</td></tr>
	</table>
	</fieldset>
	</td>
</tr>

<tr><td height=5></td></tr>
<tr>
	<td>
	<table border=0 cellpadding=0 cellspacing=0 width="100%">
	<tr>
		<td noWrap><input type=checkbox id=d_pos checked><label for=d_pos><span lang=DlgComInsertReplace></span></label></td>
		<td noWrap align=right><input type=submit class="dlgBtnCommon" value='' id=Ok onclick="ok()" lang=DlgBtnOK>&nbsp;&nbsp;<input type=button class="dlgBtnCommon" value='' onclick="window.close();" lang=DlgBtnCancel>
	</tr>
	</table>
	</td>
</tr>
</table>

</td></tr></table>

<div id=divProcessing style="width:200px;height:30px;position:absolute;left:60px;top:85px;display:none">
<table border=0 cellpadding=0 cellspacing=1 bgcolor="#000000" width="100%" height="100%"><tr><td bgcolor=#3A6EA5 align=center><marquee align="middle" behavior="alternate" scrollamount="5"><font color=#FFFFFF><span lang=DlgExcelImporting></span></font></marquee></td></tr></table>
</div>

</body>
</html>
